#!/opt/anaconda3/bin/python
# -*- coding:utf-8 -*-
'''
@project : meiguo_mall
@author  : leftxxk
#@file   : send.py
#@time   : 2021-06-01 20:48:21
'''
import requests, random


def send_sms(number, mobile):
    url = "http://106.ihuyi.com/webservice/sms.php?method=Submit"  # 请求地址
    mobile = mobile

    account = "C24225849"  # 提交账户APIID

    password = "084752a5aa6cdb4b9691e94a51195736"  # 提交密码APIKEY

    # 请求的头部
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

    # 数据整合
    data = {
        "account": account,
        "mobile": mobile,
        "password": password,
        "content": "您的验证码是：" + number + "。请不要把验证码泄露给其他人。"  # 发送的验证码短信，要注意符合模板格式，不然无法发送成功
    }  # 请求数据必须为字典类型
    # 发起请求
    response = requests.post(url=url, data=data, headers=headers)
    # 接收返回内容
    resutl = response.content.decode()
    print(resutl)


if __name__ == '__main__':
    number = str(random.randrange(1000, 9999))  # 随机生成四位验证码
    mobile = "15978530585"  # 目标手机号码
    send_sms(number, mobile)  # 调用send_sms函数

